package gp.app;

import genetic.GeneticProgram;
import genetic.treeelements.Function;
import genetic.treeelements.InputVariable;
import genetic.treeelements.Terminal;
import genetic.treeelements.functions.Addition;
import genetic.treeelements.functions.Division;
import genetic.treeelements.functions.Multiplication;
import genetic.treeelements.functions.Subtraction;

import java.io.File;
import java.util.ArrayList;
import java.util.Random;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

public class XmlSerTest {

	public static void main(String[] args) {

        // setup function set
        ArrayList<Function> functionSet = new ArrayList<Function>();
        functionSet.add(new Addition());
        functionSet.add(new Subtraction());
        functionSet.add(new Multiplication());
        functionSet.add(new Division());

        // setup input-set and desired target-set
        ArrayList<InputVariable> inputSet = new ArrayList<InputVariable>();
        InputVariable x1 = new InputVariable("x1");
//        x1.setData(XYSeriesFactory.loadFromExcel("ABB.xls", "Last", 1));
//        inputSet.add(x1);

        // setup terminal-set
        ArrayList<Terminal> terminalSet = new ArrayList<Terminal>();
        Random rd = new Random();
        for (int i=0; i<2; i++) {
            terminalSet.add(new Terminal(rd.nextDouble()*5));
        }

        GeneticProgram gp = new GeneticProgram(functionSet, inputSet, terminalSet);
        gp.createRandom(10, 0);
        
        System.out.println(gp.toString());

        Serializer serializer = new Persister();
        File result = new File("alpa_eco.xml");

        try {
        serializer.write(gp, result);
        }
        catch (Exception e) {
        	e.printStackTrace();
        	
        }
       
        

 	}

}
